<!DOCTYPE html>
<html>
  <head>
  <meta http-equiv="content-type" content="text/html; charset=utf-8">
  <meta content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" name="viewport">
  <meta name="description" content="刘清政">
  <meta name="keyword" content="hexo-theme">
  
    <link rel="shortcut icon" href="/css/images/logo.png">
  
  <title>
    
      db/MySQL系列/10-MySQL系列之-MHA高可用 | Justin-刘清政的博客
    
  </title>
  <link href="//cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.css" rel="stylesheet">
  <link href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/tomorrow.min.css" rel="stylesheet">
  
<link rel="stylesheet" href="/css/style.css">

  
    
<link rel="stylesheet" href="/css/plugins/gitment.css">

  
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/geopattern/1.2.3/js/geopattern.min.js"></script>
  <script src="//cdnjs.cloudflare.com/ajax/libs/nprogress/0.2.0/nprogress.min.js"></script>
  
    
<script src="/js/qrious.js"></script>

  
  
    
<script src="/js/gitment.js"></script>

  
  

  
<meta name="generator" content="Hexo 4.2.0"></head>
<div class="wechat-share">
  <img src="/css/images/logo.png" />
</div>

  <body>
    <header class="header fixed-header">
  <div class="header-container">
    <a class="home-link" href="/">
      <div class="logo"></div>
      <span>Justin-刘清政的博客</span>
    </a>
    <ul class="right-list">
      
        <li class="list-item">
          
            <a href="/" class="item-link">主页</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/tags/" class="item-link">标签</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/archives/" class="item-link">归档</a>
          
        </li>
      
        <li class="list-item">
          
            <a href="/about/" class="item-link">关于我</a>
          
        </li>
      
    </ul>
    <div class="menu">
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
      <span class="icon-bar"></span>
    </div>
    <div class="menu-mask">
      <ul class="menu-list">
        
          <li class="menu-item">
            
              <a href="/" class="menu-link">主页</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/tags/" class="menu-link">标签</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/archives/" class="menu-link">归档</a>
            
          </li>
        
          <li class="menu-item">
            
              <a href="/about/" class="menu-link">关于我</a>
            
          </li>
        
      </ul>
    </div>
  </div>
</header>

    <div id="article-banner">
  <h2>db/MySQL系列/10-MySQL系列之-MHA高可用</h2>



  <p class="post-date">2019-12-24</p>
    <!-- 不蒜子统计 -->
    <span id="busuanzi_container_page_pv" style='display:none' class="">
        <i class="icon-smile icon"></i> 阅读数：<span id="busuanzi_value_page_pv"></span>次
    </span>
  <div class="arrow-down">
    <a href="javascript:;"></a>
  </div>
</div>
<main class="app-body flex-box">
  <!-- Article START -->
  <article class="post-article">
    <section class="markdown-content"><h1 id="1-主从复制架构演变介绍"><a href="#1-主从复制架构演变介绍" class="headerlink" title="1.  主从复制架构演变介绍"></a>1.  主从复制架构演变介绍</h1><h2 id="1-1-基本结构"><a href="#1-1-基本结构" class="headerlink" title="1.1 基本结构"></a>1.1 基本结构</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">（1）一主一从</span><br><span class="line">（2）一主多从</span><br><span class="line">（3）多级主从</span><br><span class="line">（4）双主</span><br><span class="line">（5）循环复制</span><br></pre></td></tr></table></figure>

<h2 id="1-2-高级应用架构演变"><a href="#1-2-高级应用架构演变" class="headerlink" title="1.2 高级应用架构演变"></a>1.2 高级应用架构演变</h2><h3 id="1-2-1-高性能架构"><a href="#1-2-1-高性能架构" class="headerlink" title="1.2.1 高性能架构"></a>1.2.1 高性能架构</h3><figure class="highlight php"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">读写分离架构(读性能较高)</span><br><span class="line">代码级别</span><br><span class="line">MySQL proxy (Atlas,mysql router,proxySQL(percona),maxscale)、</span><br><span class="line">amoeba(taobao)</span><br><span class="line">xx-dbproxy等。</span><br><span class="line">分布式架构(读写性能都提高):</span><br><span class="line">分库分表——cobar---&gt;TDDL(头都大了),DRDS</span><br><span class="line">Mycat---&gt;DBLE自主研发等。</span><br><span class="line">NewSQL--&gt;TiDB</span><br></pre></td></tr></table></figure>

<h3 id="1-2-2-高可用架构"><a href="#1-2-2-高可用架构" class="headerlink" title="1.2.2  高可用架构"></a>1.2.2  高可用架构</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">（3）单活<span class="selector-pseudo">:MMM</span>架构——<span class="selector-tag">mysql-mmm</span>（<span class="selector-tag">google</span>）</span><br><span class="line">（4）单活<span class="selector-pseudo">:MHA</span>架构——<span class="selector-tag">mysql-master-ha</span>（日本<span class="selector-tag">DeNa</span>）,<span class="selector-tag">T-MHA</span></span><br><span class="line">（5）多活<span class="selector-pseudo">:MGR</span> ——5<span class="selector-class">.7</span> 新特性 <span class="selector-tag">MySQL</span> <span class="selector-tag">Group</span> <span class="selector-tag">replication</span>(5<span class="selector-class">.7</span><span class="selector-class">.17</span>) <span class="selector-tag">---</span>&gt;<span class="selector-tag">Innodb</span> <span class="selector-tag">Cluster</span>  </span><br><span class="line">（6）多活<span class="selector-pseudo">:MariaDB</span> <span class="selector-tag">Galera</span> <span class="selector-tag">Cluster</span>架构,(<span class="selector-tag">PXC</span>)<span class="selector-tag">Percona</span> <span class="selector-tag">XtraDB</span> <span class="selector-tag">Cluster</span>、<span class="selector-tag">MySQL</span> <span class="selector-tag">Cluster</span>(<span class="selector-tag">Oracle</span> <span class="selector-tag">rac</span>)架构</span><br></pre></td></tr></table></figure>

<h1 id="2-高可用MHA"><a href="#2-高可用MHA" class="headerlink" title="2. 高可用MHA       *****"></a>2. 高可用MHA       *****</h1><h2 id="2-1-架构工作原理"><a href="#2-1-架构工作原理" class="headerlink" title="2.1 架构工作原理"></a>2.1 架构工作原理</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">主库宕机处理过程</span><br><span class="line">1. 监控节点 (通过配置文件获取所有节点信息)</span><br><span class="line">   系统,网络,SSH连接性</span><br><span class="line">   主从状态,重点是主库</span><br><span class="line"></span><br><span class="line">2. 选主</span><br><span class="line">(1) 如果判断从库(position或者GTID),数据有差异,最接近于Master的slave,成为备选主</span><br><span class="line">(2) 如果判断从库(position或者GTID),数据一致,按照配置文件顺序,选主.</span><br><span class="line">(3) 如果设定有权重(candidate_master&#x3D;1),按照权重强制指定备选主.</span><br><span class="line">    1. 默认情况下如果一个slave落后master 100M的relay logs的话，即使有权重,也会失效.</span><br><span class="line">    2. 如果check_repl_delay&#x3D;0的化,即使落后很多日志,也强制选择其为备选主</span><br><span class="line">3. 数据补偿</span><br><span class="line">(1) 当SSH能连接,从库对比主库GTID 或者position号,立即将二进制日志保存至各个从节点并且应用(save_binary_logs )</span><br><span class="line">(2) 当SSH不能连接, 对比从库之间的relaylog的差异(apply_diff_relay_logs) </span><br><span class="line">4. Failover</span><br><span class="line">将备选主进行身份切换,对外提供服务</span><br><span class="line">其余从库和新主库确认新的主从关系</span><br><span class="line">5. 应用透明(VIP)</span><br><span class="line">6. 故障切换通知(send_reprt)</span><br><span class="line">7. 二次数据补偿(binlog_server)</span><br><span class="line">8. 自愈自治(待开发...)</span><br></pre></td></tr></table></figure>

<h3 id="2-2-架构介绍"><a href="#2-2-架构介绍" class="headerlink" title="2.2 架构介绍:"></a>2.2 架构介绍:</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">1主2从，master：db01   slave：db02   db03 ）：</span><br><span class="line">MHA 高可用方案软件构成</span><br><span class="line">Manager软件：选择一个从节点安装</span><br><span class="line">Node软件：所有节点都要安装</span><br></pre></td></tr></table></figure>

<h2 id="2-3-MHA软件构成"><a href="#2-3-MHA软件构成" class="headerlink" title="2.3 MHA软件构成"></a>2.3 MHA软件构成</h2><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">Manager工具包主要包括以下几个工具：</span><br><span class="line">masterha_manger             启动MHA </span><br><span class="line">masterha_check_ssh      检查MHA的SSH配置状况 </span><br><span class="line">masterha_check_repl         检查MySQL复制状况 </span><br><span class="line">masterha_master_monitor     检测master是否宕机 </span><br><span class="line">masterha_check_status       检测当前MHA运行状态 </span><br><span class="line">masterha_master_switch  控制故障转移（自动或者手动）</span><br><span class="line">masterha_conf_host      添加或删除配置的server信息</span><br><span class="line"></span><br><span class="line">Node工具包主要包括以下几个工具：</span><br><span class="line">这些工具通常由MHA Manager的脚本触发，无需人为操作</span><br><span class="line">save_binary_logs            保存和复制master的二进制日志 </span><br><span class="line">apply_diff_relay_logs       识别差异的中继日志事件并将其差异的事件应用于其他的</span><br><span class="line">purge_relay_logs            清除中继日志（不会阻塞SQL线程）</span><br></pre></td></tr></table></figure>

<h2 id="2-4-MHA环境搭建"><a href="#2-4-MHA环境搭建" class="headerlink" title="2.4  MHA环境搭建"></a>2.4  MHA环境搭建</h2><h3 id="2-4-1-规划"><a href="#2-4-1-规划" class="headerlink" title="2.4.1 规划:"></a>2.4.1 规划:</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">主库: 51    node </span><br><span class="line">从库: </span><br><span class="line">52      node</span><br><span class="line">53      node    manager</span><br></pre></td></tr></table></figure>

<h3 id="2-4-2-准备环境（略。1主2从GTID）"><a href="#2-4-2-准备环境（略。1主2从GTID）" class="headerlink" title="2.4.2 准备环境（略。1主2从GTID）"></a>2.4.2 准备环境（略。1主2从GTID）</h3><h3 id="2-4-3-配置关键程序软连接"><a href="#2-4-3-配置关键程序软连接" class="headerlink" title="2.4.3 配置关键程序软连接"></a>2.4.3 配置关键程序软连接</h3><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">ln -s /<span class="keyword">data</span>/mysql/bin/mysqlbinlog    /usr/bin/mysqlbinlog</span><br><span class="line">ln -s /<span class="keyword">data</span>/mysql/bin/mysql          /usr/bin/mysql</span><br></pre></td></tr></table></figure>

<h3 id="2-4-4-配置各节点互信"><a href="#2-4-4-配置各节点互信" class="headerlink" title="2.4.4  配置各节点互信"></a>2.4.4  配置各节点互信</h3><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br></pre></td><td class="code"><pre><span class="line">db01：</span><br><span class="line">rm -rf /root/.ssh </span><br><span class="line">ssh-keygen</span><br><span class="line">cd /root/.ssh </span><br><span class="line">mv id_rsa.pub authorized_keys</span><br><span class="line">scp  -r  /root/.ssh  <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">52</span><span class="symbol">:/root</span> </span><br><span class="line">scp  -r  /root/.ssh  <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">53</span><span class="symbol">:/root</span> </span><br><span class="line">各节点验证</span><br><span class="line"><span class="symbol">db01:</span></span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">51</span> date</span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">52</span> date</span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">53</span> date</span><br><span class="line"><span class="symbol">db02:</span></span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">51</span> date</span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">52</span> date</span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">53</span> date</span><br><span class="line"><span class="symbol">db03:</span></span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">51</span> date</span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">52</span> date</span><br><span class="line">ssh <span class="number">10.0</span>.<span class="number">0</span>.<span class="number">53</span> date</span><br></pre></td></tr></table></figure>

<h3 id="2-4-5-安装软件"><a href="#2-4-5-安装软件" class="headerlink" title="2.4.5 安装软件"></a>2.4.5 安装软件</h3><h3 id="下载mha软件"><a href="#下载mha软件" class="headerlink" title="下载mha软件"></a>下载mha软件</h3><figure class="highlight cpp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">mha官网：https:<span class="comment">//code.google.com/archive/p/mysql-master-ha/</span></span><br><span class="line">github下载地址：https:<span class="comment">//github.com/yoshinorim/mha4mysql-manager/wiki/Downloads</span></span><br></pre></td></tr></table></figure>

<h3 id="所有节点安装Node软件依赖包"><a href="#所有节点安装Node软件依赖包" class="headerlink" title="所有节点安装Node软件依赖包"></a>所有节点安装Node软件依赖包</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">yum</span> <span class="selector-tag">install</span> <span class="selector-tag">perl-DBD-MySQL</span> <span class="selector-tag">-y</span></span><br><span class="line"><span class="selector-tag">rpm</span> <span class="selector-tag">-ivh</span> <span class="selector-tag">mha4mysql-node-0</span><span class="selector-class">.56-0</span><span class="selector-class">.el6</span><span class="selector-class">.noarch</span><span class="selector-class">.rpm</span></span><br></pre></td></tr></table></figure>

<h3 id="在db01主库中创建mha需要的用户"><a href="#在db01主库中创建mha需要的用户" class="headerlink" title="在db01主库中创建mha需要的用户"></a>在db01主库中创建mha需要的用户</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">grant</span> <span class="selector-tag">all</span> <span class="selector-tag">privileges</span> <span class="selector-tag">on</span> *.* <span class="selector-tag">to</span> <span class="selector-tag">mha</span>@'10.0.0.%' identified by <span class="string">'mha'</span>;</span><br></pre></td></tr></table></figure>

<h3 id="Manager软件安装（db03）"><a href="#Manager软件安装（db03）" class="headerlink" title="Manager软件安装（db03）"></a>Manager软件安装（db03）</h3><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="selector-tag">yum</span> <span class="selector-tag">install</span> <span class="selector-tag">-y</span> <span class="selector-tag">perl-Config-Tiny</span> <span class="selector-tag">epel-release</span> <span class="selector-tag">perl-Log-Dispatch</span> <span class="selector-tag">perl-Parallel-ForkManager</span> <span class="selector-tag">perl-Time-HiRes</span></span><br><span class="line"><span class="selector-tag">rpm</span> <span class="selector-tag">-ivh</span> <span class="selector-tag">mha4mysql-manager-0</span><span class="selector-class">.56-0</span><span class="selector-class">.el6</span><span class="selector-class">.noarch</span><span class="selector-class">.rpm</span></span><br></pre></td></tr></table></figure>

<h3 id="2-4-6-配置文件准备-db03"><a href="#2-4-6-配置文件准备-db03" class="headerlink" title="2.4.6 配置文件准备(db03)"></a>2.4.6 配置文件准备(db03)</h3><figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br></pre></td><td class="code"><pre><span class="line">创建配置文件目录</span><br><span class="line"> mkdir -p /etc/mha</span><br><span class="line">创建日志目录</span><br><span class="line"> mkdir -p /<span class="keyword">var</span>/log/mha/app1</span><br><span class="line">编辑mha配置文件</span><br><span class="line">vim /etc/mha/app1.cnf</span><br><span class="line">[<span class="meta">server default</span>]</span><br><span class="line">manager_log=/<span class="keyword">var</span>/log/mha/app1/manager        </span><br><span class="line">manager_workdir=/<span class="keyword">var</span>/log/mha/app1            </span><br><span class="line">master_binlog_dir=/data/binlog       </span><br><span class="line">user=mha                                   </span><br><span class="line">password=mha                               </span><br><span class="line">ping_interval=<span class="number">2</span></span><br><span class="line">repl_password=<span class="number">123</span></span><br><span class="line">repl_user=repl</span><br><span class="line">ssh_user=root                               </span><br><span class="line">[<span class="meta">server1</span>]                                   </span><br><span class="line">hostname=<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span></span><br><span class="line">port=<span class="number">3306</span>                                  </span><br><span class="line">[<span class="meta">server2</span>]            </span><br><span class="line">hostname=<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span></span><br><span class="line">port=<span class="number">3306</span></span><br><span class="line">[<span class="meta">server3</span>]</span><br><span class="line">hostname=<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span></span><br><span class="line">port=<span class="number">3306</span></span><br></pre></td></tr></table></figure>

<h3 id="2-4-7-状态检查"><a href="#2-4-7-状态检查" class="headerlink" title="2.4.7 状态检查"></a>2.4.7 状态检查</h3><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">### 互信检查</span><br><span class="line">masterha_check_ssh  --conf=/etc/mha/app1.cnf </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [info] Reading application <span class="keyword">default</span> configuration from /etc/mha/app1.cnf..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [info] Reading server configuration from /etc/mha/app1.cnf..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [info] Starting SSH connection tests..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug] </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">36</span> <span class="number">2019</span> - [debug] </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">37</span> <span class="number">2019</span> - [debug] </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">36</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">37</span> <span class="number">2019</span> - [info] All SSH connection tests passed successfully.</span><br></pre></td></tr></table></figure>

<h3 id="主从状态检查"><a href="#主从状态检查" class="headerlink" title="主从状态检查"></a>主从状态检查</h3><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br></pre></td><td class="code"><pre><span class="line">[<span class="symbol">root@</span>db03 ~]# masterha_check_ssh  --conf=/etc/mha/app1.cnf </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [info] Reading application <span class="keyword">default</span> configuration from /etc/mha/app1.cnf..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [info] Reading server configuration from /etc/mha/app1.cnf..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [info] Starting SSH connection tests..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug] </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">34</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">36</span> <span class="number">2019</span> - [debug] </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">37</span> <span class="number">2019</span> - [debug] </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">35</span> <span class="number">2019</span> - [debug]  Connecting via SSH from <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">22</span>) to <span class="symbol">root@</span><span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">22</span>)..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">36</span> <span class="number">2019</span> - [debug]   ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">39</span>:<span class="number">37</span> <span class="number">2019</span> - [info] All SSH connection tests passed successfully.</span><br><span class="line">[<span class="symbol">root@</span>db03 ~]# masterha_check_repl  --conf=/etc/mha/app1.cnf </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">50</span> <span class="number">2019</span> - [warning] Global configuration file /etc/masterha_default.cnf not found. Skipping.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">50</span> <span class="number">2019</span> - [info] Reading application <span class="keyword">default</span> configuration from /etc/mha/app1.cnf..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">50</span> <span class="number">2019</span> - [info] Reading server configuration from /etc/mha/app1.cnf..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">50</span> <span class="number">2019</span> - [info] MHA::MasterMonitor version <span class="number">0.56</span>.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] GTID failover mode = <span class="number">1</span></span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Dead Servers:</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Alive Servers:</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]   <span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">3306</span>)</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]   <span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">3306</span>)</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]   <span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">3306</span>)</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Alive Slaves:</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]   <span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">3306</span>)  Version=<span class="number">5.7</span><span class="number">.20</span>-log (oldest major version between slaves) log-bin:enabled</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]     GTID ON</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]     Replicating from <span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">3306</span>)</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]   <span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">3306</span>)  Version=<span class="number">5.7</span><span class="number">.20</span>-log (oldest major version between slaves) log-bin:enabled</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]     GTID ON</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]     Replicating from <span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">3306</span>)</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Current Alive Master: <span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">3306</span>)</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Checking slave configurations..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]  read_only=<span class="number">1</span> <span class="keyword">is</span> not <span class="keyword">set</span> on slave <span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">3306</span>).</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]  read_only=<span class="number">1</span> <span class="keyword">is</span> not <span class="keyword">set</span> on slave <span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">3306</span>).</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Checking replication filtering settings..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]  binlog_do_db= , binlog_ignore_db= </span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]  Replication filtering check ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] GTID (with auto-pos) <span class="keyword">is</span> supported. Skipping all SSH and Node <span class="keyword">package</span> checking.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Checking SSH publickey authentication settings on the current master..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] HealthCheck: SSH to <span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span> <span class="keyword">is</span> reachable.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] </span><br><span class="line"><span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span>:<span class="number">3306</span>) (current master)</span><br><span class="line"> +--<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>:<span class="number">3306</span>)</span><br><span class="line"> +--<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>(<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>:<span class="number">3306</span>)</span><br><span class="line"></span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Checking replication health on <span class="number">10.0</span><span class="number">.0</span><span class="number">.52</span>..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]  ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Checking replication health on <span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span>..</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info]  ok.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [warning] master_ip_failover_script <span class="keyword">is</span> not defined.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [warning] shutdown_script <span class="keyword">is</span> not defined.</span><br><span class="line">Fri Apr <span class="number">19</span> <span class="number">16</span>:<span class="number">40</span>:<span class="number">51</span> <span class="number">2019</span> - [info] Got exit code <span class="number">0</span> (Not master dead).</span><br><span class="line">MySQL Replication Health <span class="keyword">is</span> OK.</span><br></pre></td></tr></table></figure>

<h3 id="2-4-8-开启MHA-db03-："><a href="#2-4-8-开启MHA-db03-：" class="headerlink" title="2.4.8  开启MHA(db03)："></a>2.4.8  开启MHA(db03)：</h3><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nohup masterha_manager --conf=<span class="regexp">/etc/mha</span><span class="regexp">/app1.cnf --remove_dead_master_conf --ignore_last_failover  &lt; /dev</span><span class="regexp">/null&gt; /var</span><span class="regexp">/log/mha</span><span class="regexp">/app1/manager</span>.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> &amp;</span><br></pre></td></tr></table></figure>

<h3 id="2-4-9-查看MHA状态"><a href="#2-4-9-查看MHA状态" class="headerlink" title="2.4.9  查看MHA状态"></a>2.4.9  查看MHA状态</h3><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line">[root@db03 ~]<span class="comment"># masterha_check_status --conf=/etc/mha/app1.cnf</span></span><br><span class="line">app1 (<span class="symbol">pid:</span><span class="number">4719</span>) is running(<span class="number">0</span><span class="symbol">:PING_OK</span>), <span class="symbol">master:</span><span class="number">10.0</span>.<span class="number">0</span>.<span class="number">51</span></span><br><span class="line">[root@db03 ~]<span class="comment"># mysql -umha -pmha -h 10.0.0.51 -e "show variables like 'server_id'"</span></span><br><span class="line"><span class="symbol">mysql:</span> [Warning] Using a password on the command line interface can be insecure.</span><br><span class="line">+---------------+-------+</span><br><span class="line"><span class="params">| Variable_name |</span> Value <span class="params">|</span></span><br><span class="line"><span class="params">+---------------+-------+</span></span><br><span class="line"><span class="params">|</span> server_id     <span class="params">| 51    |</span></span><br><span class="line">+---------------+-------+</span><br><span class="line">[root@db03 ~]<span class="comment"># mysql -umha -pmha -h 10.0.0.52 -e "show variables like 'server_id'"</span></span><br><span class="line"><span class="symbol">mysql:</span> [Warning] Using a password on the command line interface can be insecure.</span><br><span class="line">+---------------+-------+</span><br><span class="line"><span class="params">| Variable_name |</span> Value <span class="params">|</span></span><br><span class="line"><span class="params">+---------------+-------+</span></span><br><span class="line"><span class="params">|</span> server_id     <span class="params">| 52    |</span></span><br><span class="line">+---------------+-------+</span><br><span class="line">[root@db03 ~]<span class="comment"># mysql -umha -pmha -h 10.0.0.53 -e "show variables like 'server_id'"</span></span><br><span class="line"><span class="symbol">mysql:</span> [Warning] Using a password on the command line interface can be insecure.</span><br><span class="line">+---------------+-------+</span><br><span class="line"><span class="params">| Variable_name |</span> Value <span class="params">|</span></span><br><span class="line"><span class="params">+---------------+-------+</span></span><br><span class="line"><span class="params">|</span> server_id     <span class="params">| 53    |</span></span><br><span class="line">+---------------+-------+</span><br></pre></td></tr></table></figure>

<h3 id="2-4-10-故障模拟及处理"><a href="#2-4-10-故障模拟及处理" class="headerlink" title="2.4.10 故障模拟及处理"></a>2.4.10 故障模拟及处理</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">### 停主库db01:    </span></span><br><span class="line">/etc/init.d/mysqld stop</span><br><span class="line"></span><br><span class="line">观察manager  日志 tail -f /var/<span class="built_in">log</span>/mha/app1/manager</span><br><span class="line">末尾必须显示successfully，才算正常切换成功。</span><br></pre></td></tr></table></figure>

<h3 id="修复主库"><a href="#修复主库" class="headerlink" title="修复主库"></a>修复主库</h3><figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">root@db01 ~</span>]<span class="meta"># /etc/init.d/mysqld start</span></span><br></pre></td></tr></table></figure>

<h3 id="恢复主从结构"><a href="#恢复主从结构" class="headerlink" title="恢复主从结构"></a>恢复主从结构</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">CHANGE MASTER TO </span><br><span class="line">MASTER_HOST=<span class="string">'10.0.0.52'</span>,</span><br><span class="line">MASTER_PORT=3306, </span><br><span class="line">MASTER_AUTO_POSITION=1, </span><br><span class="line">MASTER_USER=<span class="string">'repl'</span>, </span><br><span class="line">MASTER_PASSWORD=<span class="string">'123'</span>;</span><br><span class="line">start slave ;</span><br></pre></td></tr></table></figure>

<h3 id="修改配置文件"><a href="#修改配置文件" class="headerlink" title="修改配置文件"></a>修改配置文件</h3><figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">[<span class="meta">server1</span>]</span><br><span class="line">hostname=<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span></span><br><span class="line">port=<span class="number">3306</span></span><br></pre></td></tr></table></figure>

<h3 id="启动MHA"><a href="#启动MHA" class="headerlink" title="启动MHA"></a>启动MHA</h3><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">nohup masterha_manager --conf=<span class="regexp">/etc/mha</span><span class="regexp">/app1.cnf --remove_dead_master_conf --ignore_last_failover  &lt; /dev</span><span class="regexp">/null&gt; /var</span><span class="regexp">/log/mha</span><span class="regexp">/app1/manager</span>.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> &amp;</span><br></pre></td></tr></table></figure>

<h3 id="2-4-11-Manager额外参数介绍"><a href="#2-4-11-Manager额外参数介绍" class="headerlink" title="2.4.11  Manager额外参数介绍"></a>2.4.11  Manager额外参数介绍</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">说明：</span><br><span class="line">主库宕机谁来接管？</span><br><span class="line">1. 所有从节点日志都是一致的，默认会以配置文件的顺序去选择一个新主。</span><br><span class="line">2. 从节点日志不一致，自动选择最接近于主库的从库</span><br><span class="line">3. 如果对于某节点设定了权重（candidate_master=1），权重节点会优先选择。</span><br><span class="line">但是此节点日志量落后主库100M日志的话，也不会被选择。可以配合check_repl_delay=0，关闭日志量的检查，强制选择候选节点。</span><br><span class="line"></span><br><span class="line">(1)  ping_interval=1</span><br><span class="line"><span class="comment">#设置监控主库，发送ping包的时间间隔，尝试三次没有回应的时候自动进行failover</span></span><br><span class="line">(2) candidate_master=1</span><br><span class="line"><span class="comment">#设置为候选master，如果设置该参数以后，发生主从切换以后将会将此从库提升为主库，即使这个主库不是集群中事件最新的slave</span></span><br><span class="line">(3)check_repl_delay=0</span><br><span class="line"><span class="comment">#默认情况下如果一个slave落后master 100M的relay logs的话，</span></span><br><span class="line">MHA将不会选择该slave作为一个新的master，因为对于这个slave的恢复需要花费很长时间，通过设置check_repl_delay=0,MHA触发切换在选择一个新的master的时候将会忽略复制延时，这个参数对于设置了candidate_master=1的主机非常有用，因为这个候选主在切换的过程中一定是新的master</span><br></pre></td></tr></table></figure>

<h3 id="2-4-12-MHA-的vip功能"><a href="#2-4-12-MHA-的vip功能" class="headerlink" title="2.4.12 MHA 的vip功能"></a>2.4.12 MHA 的vip功能</h3><h3 id="参数"><a href="#参数" class="headerlink" title="参数"></a>参数</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">master_ip_failover_script=/usr/<span class="built_in">local</span>/bin/master_ip_failover</span><br><span class="line">注意：/usr/<span class="built_in">local</span>/bin/master_ip_failover，必须事先准备好</span><br></pre></td></tr></table></figure>

<h3 id="修改脚本内容"><a href="#修改脚本内容" class="headerlink" title="修改脚本内容"></a>修改脚本内容</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">vi  /usr/<span class="built_in">local</span>/bin/master_ip_failover</span><br><span class="line">my <span class="variable">$vip</span> = <span class="string">'10.0.0.55/24'</span>;</span><br><span class="line">my <span class="variable">$key</span> = <span class="string">'1'</span>;</span><br><span class="line">my <span class="variable">$ssh_start_vip</span> = <span class="string">"/sbin/ifconfig eth0:<span class="variable">$key</span> <span class="variable">$vip</span>"</span>;</span><br><span class="line">my <span class="variable">$ssh_stop_vip</span> = <span class="string">"/sbin/ifconfig eth0:<span class="variable">$key</span> down"</span>;</span><br></pre></td></tr></table></figure>

<h3 id="更改manager配置文件："><a href="#更改manager配置文件：" class="headerlink" title="更改manager配置文件："></a>更改manager配置文件：</h3><figure class="highlight ruby"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">vi /etc/mha/app1.cnf</span><br><span class="line">添加：</span><br><span class="line">master_ip_failover_script=<span class="regexp">/usr/local</span><span class="regexp">/bin/master</span>_ip_failover</span><br><span class="line">注意：</span><br><span class="line">[root@db03 ~]<span class="comment"># dos2unix /usr/local/bin/master_ip_failover </span></span><br><span class="line"><span class="symbol">dos2unix:</span> converting file /usr/local/bin/master_ip_failover to Unix format ...</span><br><span class="line">[root@db03 ~]<span class="comment"># chmod +x /usr/local/bin/master_ip_failover</span></span><br></pre></td></tr></table></figure>

<h3 id="主库上，手工生成第一个vip地址"><a href="#主库上，手工生成第一个vip地址" class="headerlink" title="主库上，手工生成第一个vip地址"></a>主库上，手工生成第一个vip地址</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">手工在主库上绑定vip，注意一定要和配置文件中的ethN一致，我的是eth0:1(1是key指定的值)</span><br><span class="line">ifconfig eth0:1 10.0.0.55&#x2F;24</span><br></pre></td></tr></table></figure>

<h3 id="重启mha"><a href="#重启mha" class="headerlink" title="重启mha"></a>重启mha</h3><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">masterha_stop --conf=<span class="regexp">/etc/m</span>ha/app1.cnf</span><br><span class="line">nohup masterha_manager --conf=<span class="regexp">/etc/m</span>ha/app1.cnf --remove_dead_master_conf --ignore_last_failover &lt; <span class="regexp">/dev/</span><span class="literal">null</span> &gt; <span class="regexp">/var/</span>log/mha/app1/manager.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> &amp;</span><br></pre></td></tr></table></figure>

<h3 id="2-4-13-邮件提醒"><a href="#2-4-13-邮件提醒" class="headerlink" title="2.4.13 邮件提醒"></a>2.4.13 邮件提醒</h3><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="number">1.</span> 参数：</span><br><span class="line">report_script=<span class="regexp">/usr/</span>local/bin/send</span><br><span class="line"><span class="number">2.</span> 准备邮件脚本</span><br><span class="line">send_report</span><br><span class="line">(<span class="number">1</span>)准备发邮件的脚本(上传 email_2019-最新.zip中的脚本，到/usr/local/bin/中)</span><br><span class="line">(<span class="number">2</span>)将准备好的脚本添加到mha配置文件中,让其调用</span><br><span class="line"></span><br><span class="line"><span class="number">3.</span> 修改manager配置文件，调用邮件脚本</span><br><span class="line">vi /etc/mha/app1.cnf</span><br><span class="line">report_script=<span class="regexp">/usr/</span>local/bin/send</span><br><span class="line"></span><br><span class="line">（<span class="number">3</span>）停止MHA</span><br><span class="line">masterha_stop --conf=<span class="regexp">/etc/m</span>ha/app1.cnf</span><br><span class="line">（<span class="number">4</span>）开启MHA    </span><br><span class="line">nohup masterha_manager --conf=<span class="regexp">/etc/m</span>ha/app1.cnf --remove_dead_master_conf --ignore_last_failover &lt; <span class="regexp">/dev/</span><span class="literal">null</span> &gt; <span class="regexp">/var/</span>log/mha/app1/manager.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> &amp;</span><br><span class="line">        </span><br><span class="line">(<span class="number">5</span>) 关闭主库,看警告邮件  </span><br><span class="line">故障修复：</span><br><span class="line"><span class="number">1.</span> 恢复故障节点</span><br><span class="line">（<span class="number">1</span>）实例宕掉</span><br><span class="line">/etc/init.d/mysqld start </span><br><span class="line">（<span class="number">2</span>）主机损坏，有可能数据也损坏了</span><br><span class="line">备份并恢复故障节点。</span><br><span class="line"><span class="number">2.</span>恢复主从环境</span><br><span class="line">看日志文件：</span><br><span class="line">CHANGE MASTER TO MASTER_HOST=<span class="string">'10.0.0.52'</span>, MASTER_PORT=<span class="number">3306</span>, MASTER_AUTO_POSITION=<span class="number">1</span>, MASTER_USER=<span class="string">'repl'</span>, MASTER_PASSWORD=<span class="string">'123'</span>;</span><br><span class="line">start slave ;</span><br><span class="line"><span class="number">3.</span>恢复manager</span><br><span class="line"><span class="number">3.1</span> 修好的故障节点配置信息，加入到配置文件</span><br><span class="line">[server1]</span><br><span class="line">hostname=<span class="number">10.0</span><span class="number">.0</span><span class="number">.51</span></span><br><span class="line">port=<span class="number">3306</span></span><br><span class="line"><span class="number">3.2</span> 启动manager   </span><br><span class="line">nohup masterha_manager --conf=<span class="regexp">/etc/m</span>ha/app1.cnf --remove_dead_master_conf --ignore_last_failover &lt; <span class="regexp">/dev/</span><span class="literal">null</span> &gt; <span class="regexp">/var/</span>log/mha/app1/manager.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> &amp;</span><br></pre></td></tr></table></figure>

<h3 id="2-4-14-binlog-server（db03）"><a href="#2-4-14-binlog-server（db03）" class="headerlink" title="2.4.14 binlog server（db03）"></a>2.4.14 binlog server（db03）</h3><h3 id="参数："><a href="#参数：" class="headerlink" title="参数："></a>参数：</h3><figure class="highlight csharp"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br></pre></td><td class="code"><pre><span class="line">binlogserver配置：</span><br><span class="line">找一台额外的机器，必须要有<span class="number">5.6</span>以上的版本，支持gtid并开启，我们直接用的第二个slave（db03）</span><br><span class="line">vim /etc/mha/app1.cnf </span><br><span class="line">[<span class="meta">binlog1</span>]</span><br><span class="line">no_master=<span class="number">1</span></span><br><span class="line">hostname=<span class="number">10.0</span><span class="number">.0</span><span class="number">.53</span></span><br><span class="line">master_binlog_dir=/data/mysql/binlog</span><br></pre></td></tr></table></figure>

<h3 id="创建必要目录"><a href="#创建必要目录" class="headerlink" title="创建必要目录"></a>创建必要目录</h3><figure class="highlight kotlin"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">mkdir -p /<span class="keyword">data</span>/mysql/binlog</span><br><span class="line">chown -R mysql.mysql /<span class="keyword">data</span><span class="comment">/*</span></span><br><span class="line"><span class="comment">修改完成后，将主库binlog拉过来（从000001开始拉，之后的binlog会自动按顺序过来）</span></span><br></pre></td></tr></table></figure>

<h3 id="拉取主库binlog日志"><a href="#拉取主库binlog日志" class="headerlink" title="拉取主库binlog日志"></a>拉取主库binlog日志</h3><figure class="highlight bash"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="built_in">cd</span> /data/mysql/binlog     -----》必须进入到自己创建好的目录</span><br><span class="line">mysqlbinlog  -R --host=10.0.0.52 --user=mha --password=mha --raw  --stop-never mysql-bin.000001 &amp;</span><br><span class="line">注意：</span><br><span class="line">拉取日志的起点,需要按照目前从库的已经获取到的二进制日志点为起点</span><br></pre></td></tr></table></figure>

<h3 id="重启MHA"><a href="#重启MHA" class="headerlink" title="重启MHA"></a>重启MHA</h3><figure class="highlight jsx"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">masterha_stop --conf=<span class="regexp">/etc/m</span>ha/app1.cnf</span><br><span class="line">nohup masterha_manager --conf=<span class="regexp">/etc/m</span>ha/app1.cnf --remove_dead_master_conf --ignore_last_failover &lt; <span class="regexp">/dev/</span><span class="literal">null</span> &gt; <span class="regexp">/var/</span>log/mha/app1/manager.log <span class="number">2</span>&gt;&amp;<span class="number">1</span> &amp;</span><br></pre></td></tr></table></figure>

<h3 id="故障处理"><a href="#故障处理" class="headerlink" title="故障处理"></a>故障处理</h3><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">主库宕机，binlogserver 自动停掉，manager 也会自动停止。</span><br><span class="line">处理思路：</span><br><span class="line">1、重新获取新主库的binlog到binlogserver中</span><br><span class="line">2、重新配置文件binlog server信息</span><br><span class="line">3、最后再启动MHA</span><br></pre></td></tr></table></figure>

<h1 id="3-管理员在高可用架构维护的职责"><a href="#3-管理员在高可用架构维护的职责" class="headerlink" title="3.管理员在高可用架构维护的职责"></a>3.管理员在高可用架构维护的职责</h1><figure class="highlight css"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">1. 搭建：<span class="selector-tag">MHA</span>+<span class="selector-tag">VIP</span>+<span class="selector-tag">SendReport</span>+<span class="selector-tag">BinlogServer</span></span><br><span class="line">2. 监控及故障处理</span><br><span class="line">3.  高可用架构的优化</span><br><span class="line"> 核心是：尽可能降低主从的延时，让<span class="selector-tag">MHA</span>花在数据补偿上的时间尽量减少。</span><br><span class="line">5<span class="selector-class">.7</span> 版本，开启<span class="selector-tag">GTID</span>模式，开启从库<span class="selector-tag">SQL</span>并发复制。</span><br></pre></td></tr></table></figure>



<p>作者：wwwoldguocom<br>链接：<a href="https://www.jianshu.com/p/0f7b5a962ba7" target="_blank" rel="noopener">https://www.jianshu.com/p/0f7b5a962ba7</a><br>来源：简书<br>著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。</p>
</section>
    <!-- Tags START -->
    
    <!-- Tags END -->
    <!-- NAV START -->
    
  <div class="nav-container">
    <!-- reverse left and right to put prev and next in a more logic postition -->
    
      <a class="nav-left" href="/db/MySQL%E7%B3%BB%E5%88%97/07-MySQL%E7%B3%BB%E5%88%97%E4%B9%8B-%E5%A4%87%E4%BB%BD%E6%81%A2%E5%A4%8D/">
        <span class="nav-arrow">← </span>
        
          db/MySQL系列/07-MySQL系列之-备份恢复
        
      </a>
    
    
      <a class="nav-right" href="/db/MySQL%E7%B3%BB%E5%88%97/11-MySQL%E7%B3%BB%E5%88%97%E4%B9%8B-%E8%AF%BB%E5%86%99%E5%88%86%E7%A6%BB%E6%9E%B6%E6%9E%84-Atlas/">
        
          db/MySQL系列/11-MySQL系列之-读写分离架构-Atlas
        
        <span class="nav-arrow"> →</span>
      </a>
    
  </div>

    <!-- NAV END -->
    <!-- 打赏 START -->
    
      <div class="money-like">
        <div class="reward-btn">
          赏
          <span class="money-code">
            <span class="alipay-code">
              <div class="code-image"></div>
              <b>使用支付宝打赏</b>
            </span>
            <span class="wechat-code">
              <div class="code-image"></div>
              <b>使用微信打赏</b>
            </span>
          </span>
        </div>
        <p class="notice">点击上方按钮,请我喝杯咖啡！</p>
      </div>
    
    <!-- 打赏 END -->
    <!-- 二维码 START -->
    
      <div class="qrcode">
        <canvas id="share-qrcode"></canvas>
        <p class="notice">扫描二维码，分享此文章</p>
      </div>
    
    <!-- 二维码 END -->
    
      <!-- Gitment START -->
      <div id="comments"></div>
      <!-- Gitment END -->
    
  </article>
  <!-- Article END -->
  <!-- Catalog START -->
  
    <aside class="catalog-container">
  <div class="toc-main">
  <!-- 不蒜子统计 -->
    <strong class="toc-title">目录</strong>
    
      <ol class="toc-nav"><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#1-主从复制架构演变介绍"><span class="toc-nav-text">1.  主从复制架构演变介绍</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#1-1-基本结构"><span class="toc-nav-text">1.1 基本结构</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#1-2-高级应用架构演变"><span class="toc-nav-text">1.2 高级应用架构演变</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-2-1-高性能架构"><span class="toc-nav-text">1.2.1 高性能架构</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#1-2-2-高可用架构"><span class="toc-nav-text">1.2.2  高可用架构</span></a></li></ol></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#2-高可用MHA"><span class="toc-nav-text">2. 高可用MHA       *****</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-1-架构工作原理"><span class="toc-nav-text">2.1 架构工作原理</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-2-架构介绍"><span class="toc-nav-text">2.2 架构介绍:</span></a></li></ol></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-3-MHA软件构成"><span class="toc-nav-text">2.3 MHA软件构成</span></a></li><li class="toc-nav-item toc-nav-level-2"><a class="toc-nav-link" href="#2-4-MHA环境搭建"><span class="toc-nav-text">2.4  MHA环境搭建</span></a><ol class="toc-nav-child"><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-1-规划"><span class="toc-nav-text">2.4.1 规划:</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-2-准备环境（略。1主2从GTID）"><span class="toc-nav-text">2.4.2 准备环境（略。1主2从GTID）</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-3-配置关键程序软连接"><span class="toc-nav-text">2.4.3 配置关键程序软连接</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-4-配置各节点互信"><span class="toc-nav-text">2.4.4  配置各节点互信</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-5-安装软件"><span class="toc-nav-text">2.4.5 安装软件</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#下载mha软件"><span class="toc-nav-text">下载mha软件</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#所有节点安装Node软件依赖包"><span class="toc-nav-text">所有节点安装Node软件依赖包</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#在db01主库中创建mha需要的用户"><span class="toc-nav-text">在db01主库中创建mha需要的用户</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#Manager软件安装（db03）"><span class="toc-nav-text">Manager软件安装（db03）</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-6-配置文件准备-db03"><span class="toc-nav-text">2.4.6 配置文件准备(db03)</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-7-状态检查"><span class="toc-nav-text">2.4.7 状态检查</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#主从状态检查"><span class="toc-nav-text">主从状态检查</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-8-开启MHA-db03-："><span class="toc-nav-text">2.4.8  开启MHA(db03)：</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-9-查看MHA状态"><span class="toc-nav-text">2.4.9  查看MHA状态</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-10-故障模拟及处理"><span class="toc-nav-text">2.4.10 故障模拟及处理</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#修复主库"><span class="toc-nav-text">修复主库</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#恢复主从结构"><span class="toc-nav-text">恢复主从结构</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#修改配置文件"><span class="toc-nav-text">修改配置文件</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#启动MHA"><span class="toc-nav-text">启动MHA</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-11-Manager额外参数介绍"><span class="toc-nav-text">2.4.11  Manager额外参数介绍</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-12-MHA-的vip功能"><span class="toc-nav-text">2.4.12 MHA 的vip功能</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#参数"><span class="toc-nav-text">参数</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#修改脚本内容"><span class="toc-nav-text">修改脚本内容</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#更改manager配置文件："><span class="toc-nav-text">更改manager配置文件：</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#主库上，手工生成第一个vip地址"><span class="toc-nav-text">主库上，手工生成第一个vip地址</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#重启mha"><span class="toc-nav-text">重启mha</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-13-邮件提醒"><span class="toc-nav-text">2.4.13 邮件提醒</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#2-4-14-binlog-server（db03）"><span class="toc-nav-text">2.4.14 binlog server（db03）</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#参数："><span class="toc-nav-text">参数：</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#创建必要目录"><span class="toc-nav-text">创建必要目录</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#拉取主库binlog日志"><span class="toc-nav-text">拉取主库binlog日志</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#重启MHA"><span class="toc-nav-text">重启MHA</span></a></li><li class="toc-nav-item toc-nav-level-3"><a class="toc-nav-link" href="#故障处理"><span class="toc-nav-text">故障处理</span></a></li></ol></li></ol></li><li class="toc-nav-item toc-nav-level-1"><a class="toc-nav-link" href="#3-管理员在高可用架构维护的职责"><span class="toc-nav-text">3.管理员在高可用架构维护的职责</span></a></li></ol>
    
  </div>
</aside>
  
  <!-- Catalog END -->
</main>

<script>
  (function () {
    var url = 'http://www.liuqingzheng.top/db/MySQL系列/10-MySQL系列之-MHA高可用/';
    var banner = ''
    if (banner !== '' && banner !== 'undefined' && banner !== 'null') {
      $('#article-banner').css({
        'background-image': 'url(' + banner + ')'
      })
    } else {
      $('#article-banner').geopattern(url)
    }
    $('.header').removeClass('fixed-header')

    // error image
    $(".markdown-content img").on('error', function() {
      $(this).attr('src', 'http://file.muyutech.com/error-img.png')
      $(this).css({
        'cursor': 'default'
      })
    })

    // zoom image
    $(".markdown-content img").on('click', function() {
      var src = $(this).attr('src')
      if (src !== 'http://file.muyutech.com/error-img.png') {
        var imageW = $(this).width()
        var imageH = $(this).height()

        var zoom = ($(window).width() * 0.95 / imageW).toFixed(2)
        zoom = zoom < 1 ? 1 : zoom
        zoom = zoom > 2 ? 2 : zoom
        var transY = (($(window).height() - imageH) / 2).toFixed(2)

        $('body').append('<div class="image-view-wrap"><div class="image-view-inner"><img src="'+ src +'" /></div></div>')
        $('.image-view-wrap').addClass('wrap-active')
        $('.image-view-wrap img').css({
          'width': `${imageW}`,
          'transform': `translate3d(0, ${transY}px, 0) scale3d(${zoom}, ${zoom}, 1)`
        })
        $('html').css('overflow', 'hidden')

        $('.image-view-wrap').on('click', function() {
          $(this).remove()
          $('html').attr('style', '')
        })
      }
    })
  })();
</script>


  <script>
    var qr = new QRious({
      element: document.getElementById('share-qrcode'),
      value: document.location.href
    });
  </script>



  <script>
    var gitmentConfig = "liuqingzheng";
    if (gitmentConfig !== 'undefined') {
      var gitment = new Gitment({
        id: "db/MySQL系列/10-MySQL系列之-MHA高可用",
        owner: "liuqingzheng",
        repo: "FuckBlog",
        oauth: {
          client_id: "32a4076431cf39d0ecea",
          client_secret: "94484bd79b3346a949acb2fda3c8a76ce16990c6"
        },
        theme: {
          render(state, instance) {
            const container = document.createElement('div')
            container.lang = "en-US"
            container.className = 'gitment-container gitment-root-container'
            container.appendChild(instance.renderHeader(state, instance))
            container.appendChild(instance.renderEditor(state, instance))
            container.appendChild(instance.renderComments(state, instance))
            container.appendChild(instance.renderFooter(state, instance))
            return container;
          }
        }
      })
      gitment.render(document.getElementById('comments'))
    }
  </script>




    <div class="scroll-top">
  <span class="arrow-icon"></span>
</div>
    <footer class="app-footer">
<!-- 不蒜子统计 -->
<span id="busuanzi_container_site_pv">
     本站总访问量<span id="busuanzi_value_site_pv"></span>次
</span>
<span class="post-meta-divider">|</span>
<span id="busuanzi_container_site_uv" style='display:none'>
     本站访客数<span id="busuanzi_value_site_uv"></span>人
</span>
<script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>



  <p class="copyright">
    &copy; 2021 | Proudly powered by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank">小猿取经</a>
    <br>
    Theme by <a href="https://www.cnblogs.com/xiaoyuanqujing" target="_blank" rel="noopener">小猿取经</a>
  </p>
</footer>

<script>
  function async(u, c) {
    var d = document, t = 'script',
      o = d.createElement(t),
      s = d.getElementsByTagName(t)[0];
    o.src = u;
    if (c) { o.addEventListener('load', function (e) { c(null, e); }, false); }
    s.parentNode.insertBefore(o, s);
  }
</script>
<script>
  async("//cdnjs.cloudflare.com/ajax/libs/fastclick/1.0.6/fastclick.min.js", function(){
    FastClick.attach(document.body);
  })
</script>

<script>
  var hasLine = 'true';
  async("//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js", function(){
    $('figure pre').each(function(i, block) {
      var figure = $(this).parents('figure');
      if (hasLine === 'false') {
        figure.find('.gutter').hide();
      }
      var lang = figure.attr('class').split(' ')[1] || 'code';
      var codeHtml = $(this).html();
      var codeTag = document.createElement('code');
      codeTag.className = lang;
      codeTag.innerHTML = codeHtml;
      $(this).attr('class', '').empty().html(codeTag);
      figure.attr('data-lang', lang.toUpperCase());
      hljs.highlightBlock(block);
    });
  })
</script>





<!-- Baidu Tongji -->

<script>
    var _baId = 'c5fd96eee1193585be191f318c3fa725';
    // Originial
    var _hmt = _hmt || [];
    (function() {
      var hm = document.createElement("script");
      hm.src = "//hm.baidu.com/hm.js?" + _baId;
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(hm, s);
    })();
</script>


<script src="/js/script.js"></script>


<script src="/js/search.js"></script>


<script src="/js/load.js"></script>



  <span class="local-search local-search-google local-search-plugin" style="right: 50px;top: 70px;;position:absolute;z-index:2;">
      <input type="search" placeholder="站内搜索" id="local-search-input" class="local-search-input-cls" style="">
      <div id="local-search-result" class="local-search-result-cls"></div>
  </span>


  </body>
</html>